<?php
/**
 * @authors alex (20779512@qq.com)
 * @date    2014-04-15 08:58:26
 * @version 1.0
 */

class DispatchAction extends AdminAction {
    
    public function index(){
		$obj = M('Dispatch');
		$count = $obj->count();
		import("@.ORG.Page");
		$page = new Page($count, 20);
		$show = $page->show();
		$list = $obj->order('sort asc , id desc')->limit($page->firstRow . ',' . $page->listRows)->select();
		$this->assign('list', $list);
		$this->assign('page', $show);
		$this->assign('keyword', $keyword);
		$this->display();
    }

    #添加
	public function add(){
		$this->display();
	}

	#保存
	public function save(){
		$this->all_add('Dispatch',U('Dispatch/index'));
	}

	#编辑
	public function edit(){
		$id = (int) $_GET['id'];
		if (!isset ($id)) {
			$this->error('参数错误');
		}
		$obj = M('Dispatch');

		$list = $obj->where("id=$id")->find();

		if (!$list) {
			$this->error('信息不存在');
		} else {
			$this->assign('list', $list);
			$this->display();
		}
	}
	
	#更新
	public function update() {
		$this->all_save('Dispatch',U('Dispatch/index'));
	}

	#删除
	public function del(){

		$id=I('post.selectedids');

		if($id==''){
			$state = "您没有选择任何信息！";
		}else{
			$obj = M('Dispatch');
			foreach ($id as $v) {
				$map['id'] = $v;				
				$obj->where($map)->delete();
			}
			$state = 'SUCCESS';
	        $message = '删除成功';
	        $url = U('Dispatch/index');
		}
		echo $this->echo_json_str($state,$message,$url);
	}
}